﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.stmtformatter;
using SharpSqlAnalyzer.pp.utils;

namespace SharpSqlAnalyzer.pp.processor.type.comm
{
	// Token: 0x02000256 RID: 598
	public class StmtListProcessor : AbstractProcessor
	{
		// Token: 0x06001340 RID: 4928 RVA: 0x0031E51C File Offset: 0x0031C71C
		public override void process(TParseTreeNode nodeArg)
		{
			TStatementList tstatementList = nodeArg as TStatementList;
			string parameter = this.getParameter<string>(typeof(string));
			int num = -1;
			for (int i = 0; i < tstatementList.size(); i++)
			{
				TCustomSqlStatement tcustomSqlStatement = tstatementList.get(i);
				if (tcustomSqlStatement != null && tcustomSqlStatement.ParentStmt != null && tcustomSqlStatement.startToken != null && tcustomSqlStatement.endToken != null)
				{
					if (tcustomSqlStatement.ParentStmt.GSharpSqlParser.DbVendor == EDbVendor.dbvmssql)
					{
						return;
					}
					if (num == -1 && parameter != null)
					{
						TSourceToken tsourceToken = SourceTokenSearcher.firstSelectedToken(tcustomSqlStatement.ParentStmt.startToken.container, tcustomSqlStatement.ParentStmt.startToken.posinlist, tcustomSqlStatement.ParentStmt.endToken.posinlist, parameter);
						if (tsourceToken == null)
						{
							tsourceToken = tcustomSqlStatement.ParentStmt.startToken;
						}
						if (tsourceToken != null)
						{
							num = SourceTokenOperator.curColumnNumberVT(tsourceToken.container, tsourceToken.posinlist);
						}
					}
					if (parameter != null && num != -1)
					{
						SourceTokenOperator.removeWhitespaceAndReturnFromEnd(this.Option, tcustomSqlStatement.startToken);
						SourceTokenOperator.addBefore(this.Option, tcustomSqlStatement.startToken, SourceTokenOperator.createReturnSourceToken());
						SourceTokenOperator.addBefore(this.Option, tcustomSqlStatement.startToken, SourceTokenOperator.createWhitespaceSourceToken(num + this.Option.indentLen));
					}
					FormatterFactory.processStatement(this.Option, tstatementList.get(i));
				}
			}
		}
	}
}
